<?

//conect to mysql
$db = mysql_connect("localhost", "usr_2012_16", "se09member");
if (!$db) {
	print "Error - Could not connect to MySQL";
	exit;
}
// Select the database
$er = mysql_select_db("db_2012_16");
if (!$er) {
	print "Error - Could not select the database db_2012_16";
	exit;
}

$id = $HTTP_RAW_POST_DATA;

$query_content = "select content from se_exercise_content where exercise_id = $id order by line_number;";
$content = mysql_query($query_content);        
$lines = array();
while ($row_content = mysql_fetch_array($content)) {
    array_push($lines, $row_content['content']);    
    print $row_content['content']."\n";
}

print "\n";

foreach ($lines as $line) {
    for ($pos = 0; $pos < strlen($line); $pos += 3) {
        $char = substr($line, $pos, 3);
        $query_ans = "select goal_key from se_dictionary where goal_char = '$char';";
        $result = mysql_query($query_ans);
        while ($row = mysql_fetch_array($result)) {
            $goal_key = $row['goal_key'];
            print "$char $goal_key\n";
        }
    }
}

?>
